/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Entity;

import java.io.Serializable;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 *
 * @author ori
 */
@Entity
@Table(name = "Friends")
@NamedQueries({@NamedQuery(name = "Friends.findAll", query = "SELECT f FROM Friends f"), 
@NamedQuery(name = "Friends.findByUserNameAndfriend", query = "SELECT f FROM Friends f WHERE f.friendsPK.userName = :userName AND f.friendsPK.friend = :friendName"),
@NamedQuery(name = "Friends.findByUserName", query = "SELECT f FROM Friends f WHERE f.friendsPK.userName = :userName ORDER BY f.player.accumScore DESC"),
@NamedQuery(name = "Friends.findOnlineByUserName", query = "SELECT f FROM Friends f WHERE f.friendsPK.userName = :userName AND f.player.isOnline = 1 ORDER BY f.player.accumScore DESC"),
@NamedQuery(name = "Friends.findByFriend", query = "SELECT f FROM Friends f WHERE f.friendsPK.friend = :friend")})
public class Friends implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected FriendsPK friendsPK;
    @JoinColumn(name = "friend", referencedColumnName = "playName", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Player player;

    public Friends() {
    }

    public Friends(FriendsPK friendsPK) {
        this.friendsPK = friendsPK;
    }

    public Friends(String userName, String friend) {
        this.friendsPK = new FriendsPK(userName, friend);
    }
    
    public FriendsPK getFriendsPK() {
        return friendsPK;
    }

    public void setFriendsPK(FriendsPK friendsPK) {
        this.friendsPK = friendsPK;
    }

    public Player getPlayer() {
        return player;
    }

    public void setPlayer(Player player) {
        this.player = player;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (friendsPK != null ? friendsPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Friends)) {
            return false;
        }
        Friends other = (Friends) object;
        if ((this.friendsPK == null && other.friendsPK != null) || (this.friendsPK != null && !this.friendsPK.equals(other.friendsPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entity.Friends[friendsPK=" + friendsPK + "]";
    }

}
